define(["jquery","vue","layer",'common'],function ($,Vue,layer,common){
    const Controller = {
        index:function (){
            // console.log(111111111111111111111111)
            var app = Vue.createApp({
                data(){
                    return {
                        urls:{
                            config:Config,
                            get_url:"auth.rule/index",
                            multi_url:"auth.rule/multi",
                            del_url:"auth.rule/del",
                            edit_url:"auth.rule/edit",
                        },
                        dataObj:{
                            total:0,
                            rows:[],
                            limit:10,
                            page:1
                        },
                       dataList:[],
                        page:0,
                        iconlist:[]
                    }
                },
                created(){
                    // console.log(Config,'99999999999999')
                    // console.log(999999999999999999)
                    // this.getRuleList()
                    this.selectMainUrl()
                    this.indexLoadData()
                    this.indexCreateHeight(80)
                },
                methods:{
                    ...common,
                    ScanMenu(){
                        let url = "scan_menu"
                        let that = this
                        this.$messageBox.confirm("扫描菜单需要花费较长时间，请确认！","提示",{
                            confirmButtonText: '确定',
                            cancelButtonText: '取消',
                            type:"success"
                        }).then(()=>{
                            $.post(url,{},function (res) {
                                // console.log(res)
                                if(res.code==1){
                                    that.$message({
                                        message: res.msg?res.msg:"操作成功",
                                        type: 'success'
                                    })
                                    that.indexLoadData()
                                    parent.getAllMenus();
                                }else{
                                    that.$message({
                                        message: res.msg?res.msg:"操作成功",
                                        type: 'error'
                                    })
                                }
                            })
                        }).catch(err=>{

                        })
                        // $.post(url,{},function (res) {
                        //     console.log(res)
                        // })
                    },
                    test(){
                      let url = 'test';
                      $.get(url,function (res){
                          console.log(res)
                      })
                    },
                    handleAdd(){
                        let url = Config.controllername+'/add'
                        let that = this;
                        this.open2(url,{
                            title:"添加",
                            callback:function (res){
                                that.indexLoadData()
                                window.parent.getAllMenus()
                                // console.log(window.parent)
                            }
                        })
                    },
                    getRuleList(){
                        // console.log(Config.moduleurl+'/'+this.urls.get_url,'cccccccccccccccccc')
                        // let url = Config.moduleurl+'/'+this.urls.get_url
                        // let that = this;
                        // $.get(url,function (res){
                        //     // console.log(res)
                        //     if(res.code==1){
                        //         that.dataList = res.data;
                        //     }
                        //     // that.dataList = res;
                        // })
                    },
                    handleEdit(row){
                        // console.log(row)
                        let that = this
                        let url = Config.controllername+`/edit?ids=${row.id}`
                        // let url = this.urls.edit_url+`?ids=${row.id}`;
                        this.open2(url,{
                            area:["50%","90%"],
                            title:"编辑",
                            callback:function (res){
                                that.indexLoadData()
                                window.parent.getAllMenus()
                            }
                        })
                    },
                    handleDelete(row){
                        console.log(row)
                        let that = this;
                        layer.confirm('确定删除吗？', function(index){
                            if(index){
                                let url = Config.moduleurl+'/'+that.urls.del_url+`?ids=${row.id}`
                                $.post(url,function (res){
                                    if(res.code==1){
                                        layer.msg(res.msg)
                                        that.indexLoadData()
                                        window.parent.getAllMenus()
                                        // console.log(window.parent)
                                    }
                                })
                            }
                        });
                    },
                    changeSwitich(status,row,field){
                        let that = this;
                        let url = Config.moduleurl+'/'+this.urls.multi_url+`?ids=${row.id}`
                        $.post(url,{params:`${field}=${status}`,action:"",ids:row.id},function (res){
                            if(res.code==1){
                                that.indexLoadData()
                                window.parent.getAllMenus()
                                return true
                            }else{
                                layer.msg(res.msg)
                                let dataList = that.dataList
                                dataList.forEach(item=>{
                                    if(item.id==row.id){
                                        item[field] = !status
                                    }
                                })
                                that.dataList = dataList
                            }
                        })
                    },
                    iconUpdate(){
                        let that = this;
                        if(this.page==0){
                            this.iconlist = common.getELEMENTIcon()
                        }
                        let data = this.iconlist.slice(0,100);
                        $.post(Config.moduleurl+'/index/set_icon',{data:data},function (res){
                            if(res.code==1){
                                that.page += 1;
                                that.iconlist.splice(0,100)
                                that.iconUpdate()
                            }
                        })

                    },
                    showIcon(){
                        let url = Config.moduleurl+'/index/get_icon';
                        this.open2(url,{
                            title:"图标选择",
                            callback:function (res){
                                console.log(res,'这里是rule。showIcon')
                            }
                        })
                    },
                    jt(icon){
                        console.log(icon,'这里是rule。jt')
                    }
                }
            })
            common.loadELEMENT(app,['icon'])
            app.mount("#app");
        },
        add:function (){
            var app = Vue.createApp({
                data(){
                    return {
                        form:{
                            title:"",
                            name:"",
                            module:"",
                            route:"",
                            icon:"",
                            remark:"",
                            ismenu:"",
                            status:1,
                            weigh:"",
                            pid:null
                        },
                        rules:{
                            title:[
                                { required: true, message: '请输入菜单名称', trigger: 'blur' },
                            ],
                            name:[
                                { required: true, message: '请输入菜单标识', trigger: 'blur' },
                            ],
                            module:[
                                { required: true, message: '请选择模块', trigger: 'blur' },
                            ]
                        },
                        modules:[],
                        menus:[]
                    }
                },
                created(){
                    // this.getFormInfo()
                    this.getmodules()
                    this.getMenus()
                    // console.log(this.form,'ffffffffffffffff')
                },
                methods:{
                    ...common,
                    getMenus(){
                        let url = 'auth.rule/index';
                        let that = this;
                        let data = [{
                            field:"keyField",
                            value:"id"
                        },{
                            field:"isTree",
                            value:1
                        },{
                            field:"custom",
                            value:{
                                ismenu:1,
                                status:1
                            }
                        }
                        ]
                        data = this.createSeachParams(data)
                        // return
                        this.moduleGet(url,data,function (res){
                            let menus = [
                                {
                                    id:0,
                                    title:"顶级菜单",
                                }
                            ]
                            menus = menus.concat(res.list)
                            that.menus = menus;
                        })
                    },
                    getmodules(){
                        let url = 'auth.rule/get_modules';
                        let that = this
                        this.moduleGet(url,function (res){
                            if(res.code==1){
                                // let data = res.data;
                                that.modules =res.data;
                            }
                        })
                    },
                    onSubmitSave:function (){
                        this.formSubmit()
                    },
                    showIcon(){
                        let url = 'index/get_icon';
                        let that = this;
                        this.open2(url,{
                            title:"图标选择",
                            area:['100%','100%'],
                            callback:function (res){
                                console.log(res,'这里是rule。showIcon')
                                that.form.icon = res;
                            }
                        })
                    }
                }
            })
            common.loadELEMENT(app,['icon'])
            
            app.mount("#app");
        },
        edit:function (){
            var app = Vue.createApp({
                data(){
                    return {
                        form:{
                            title:"",
                            name:"",
                            module:"",
                            route:"",
                            icon:"",
                            remark:"",
                            ismenu:"",
                            status:'',
                            weigh:"",
                            pid:null
                        },
                        rules:{
                            title:[
                                { required: true, message: '请输入菜单名称', trigger: 'blur' },
                            ],
                            name:[
                                { required: true, message: '请输入菜单标识', trigger: 'blur' },
                            ],
                            module:[
                                { required: true, message: '请选择模块', trigger: 'blur' },
                            ]
                        },
                        modules:[],
                        menus:[]
                    }
                },
                created(){
                    console.log("9999999999999999999999999")
                    // this.getFormInfo()
                    this.getEditData()
                   this.getmodules()
                   this.getMenus()
                   // console.log(this.form,'ffffffffffffffff')
               },
                methods:{
                    ...common,
                    getMenus(){
                        let url = 'auth.rule/index';
                        let that = this;
                        let data = [{
                                field:"keyField",
                                value:"id"
                            },{
                                field:"isTree",
                                value:1
                            },{
                            field:"custom",
                            value:{
                                ismenu:1,
                                status:1
                            }
                        }
                        ]
                        data = this.createSeachParams(data)
                        // return
                        this.moduleGet(url,data,function (res){
                            let menus = [
                                {
                                    id:0,
                                    title:"顶级菜单",
                                }
                            ]
                            menus = menus.concat(res.list)
                            that.menus = menus;
                        })
                    },
                    getmodules(){
                        let url = 'auth.rule/get_modules';
                        let that = this
                        this.moduleGet(url,function (res){
                            if(res.code==1){
                                // let data = res.data;
                                that.modules =res.data;
                            }
                        })
                    },
                    showIcon(){
                        let url = 'index/get_icon';
                        let that = this;
                        this.open2(url,{
                            title:"图标选择",
                            area:['100%','100%'],
                            callback:function (res){
                                console.log(res,'这里是rule。showIcon')
                                that.form.icon = res;
                            }
                        })
                    }
                }
            })
            common.loadELEMENT(app,['icon'])
            
            app.mount("#app");
        }
    }
    return Controller
})